/*
 * Copyright (c) 2019. Mikes. All rights reserved.
 *
 * You can contact me with sending email to bWlrZXNfMjAxMkAxNjMuY29t for more information!
 */

package com.climber.android.commonsdk.api

import com.climber.android.commonsdk.api.entity.Token
import com.climber.android.commonsdk.app.AppConstants
import io.ganguo.library.mvp.Config
import io.ganguo.library.mvp.util.GsonUtils
import io.ganguo.library.mvp.util.StringUtils

/**
 * Created by Mikes at 2019-11-04 16:10
 */
object AccountToken{
    var loginToken: Token? = null
        get() {
            val tokenStr = Config.getString(AppConstants.config_Token)
            return if (StringUtils.isNotEmpty(tokenStr)) {
                GsonUtils.fromJson(tokenStr, Token::class.java)
            } else {
                null
            }
        }
        set(value) {
            field = value
            if (value != null) {
                Config.putString(AppConstants.config_Token, GsonUtils.toJson(value))
            } else {
                Config.remove(AppConstants.config_Token)
            }
        }
}